#ifndef ROCKET_NET_TIMER_H
#define ROCKET_NET_TIMER_H

#include <map>

#include "../common/mutex.h"
#include "fd_event.h"
#include "timer_event.h"

namespace rocket {

class Timer : public FdEvent {
  public:
    Timer();

    Timer(int fd);

    ~Timer();

    void addTimerEvent(TimerEvent::s_ptr event);

    void deleteTimerEvent(TimerEvent::s_ptr event);

    void onTimer(); // 发生 IO 事件后 eventloop 执行回调函数

  private:
    void resetArriveTime();

  private:
    std::multimap<int64_t, TimerEvent::s_ptr> m_pending_events;

    Mutex m_mutex;
};

} // namespace rocket

#endif
